package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.ServiceDictionaryItemEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 服务字典关联表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class ServiceDictionaryItemProvider {

    /**
     * 增加ServiceDictionaryItem
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertServiceDictionaryItem(@Param("entity") ServiceDictionaryItemEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" service_dictionary_item ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" data_dictionary_id ", " #{entity.dataDictionaryId,jdbcType=INTEGER} ");
                VALUES(" service_item_id ", " #{entity.serviceItemId,jdbcType=INTEGER} ");
                VALUES(" purpose ", " #{entity.purpose,jdbcType=VARCHAR} ");
                VALUES(" rule_code ", " #{entity.ruleCode,jdbcType=VARCHAR} ");
                VALUES(" rule_type ", " #{entity.ruleType,jdbcType=VARCHAR} ");
                VALUES(" rule_describe ", " #{entity.ruleDescribe} ");
                VALUES(" rule_params ", " #{entity.ruleParams} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ServiceDictionaryItem
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateServiceDictionaryItem(@Param("entity") ServiceDictionaryItemEntity entity) {
        return new SQL() {
            {
                UPDATE(" service_dictionary_item ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" data_dictionary_id = #{entity.dataDictionaryId,jdbcType=INTEGER} ");
                SET(" service_item_id = #{entity.serviceItemId,jdbcType=INTEGER} ");
                SET(" purpose = #{entity.purpose,jdbcType=VARCHAR} ");
                SET(" rule_code = #{entity.ruleCode,jdbcType=VARCHAR} ");
                SET(" rule_type = #{entity.ruleType,jdbcType=VARCHAR} ");
                SET(" rule_describe = #{entity.ruleDescribe} ");
                SET(" rule_params = #{entity.ruleParams} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ServiceDictionaryItem列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listServiceDictionaryItem(@Param("entity") ServiceDictionaryItemEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,data_dictionary_id,service_item_id,purpose,rule_code,rule_type,rule_describe,rule_params,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" service_dictionary_item ");

                if (entity.getDataDictionaryId() != null) {
                    WHERE(" data_dictionary_id = #{entity.dataDictionaryId,jdbcType=INTEGER} ");
                }

                if (entity.getServiceItemId() != null) {
                    WHERE(" service_item_id = #{entity.serviceItemId,jdbcType=INTEGER} ");
                }

                if (entity.getPurpose() != null) {
                    WHERE(" purpose = #{entity.purpose,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleCode() != null) {
                    WHERE(" rule_code = #{entity.ruleCode,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleType() != null) {
                    WHERE(" rule_type = #{entity.ruleType,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleDescribe() != null) {
                    WHERE(" rule_describe = #{entity.ruleDescribe} ");
                }

                if (entity.getRuleParams() != null) {
                    WHERE(" rule_params = #{entity.ruleParams} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}